<script setup lang="ts">
const route = useRoute()
const router = useRouter()

function onBack() {
  if (window.history.state.back) {
    history.back()
  } else {
    router.replace('/')
  }
}

const { t } = useI18n()

const title = computed(() => {
  if (!route.meta) {
    return ''
  }

  const result = route.meta.i18n ? t(route.meta.i18n) : route.meta.title || ''
  return result
})
</script>

<template>
  <VanNavBar v-show="title" :title="title" :fixed="true" clickable left-arrow @click-left="onBack" />
</template>
